//package tw.spring.demo.service.converter;
//
//import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.springframework.http.HttpInputMessage;
//import org.springframework.http.HttpOutputMessage;
//import org.springframework.http.MediaType;
//import org.springframework.http.converter.AbstractHttpMessageConverter;
//import org.springframework.http.converter.HttpMessageNotReadableException;
//import org.springframework.http.converter.HttpMessageNotWritableException;
//import org.springframework.stereotype.Service;
//import tw.spring.demo.model.AjaxResponse;
//
//import java.io.IOException;
//
///**
// * @author: 陈艺博
// * @date: 2021-02-04 19:26
// * @description: 声明@ResponseBody后。 数据按照excel方式返回
// **/
//
//@Service
//public class XlsToHttpMessageConverter extends AbstractHttpMessageConverter<AjaxResponse> {
//
//    private static final MediaType EXCEL_TYPE = MediaType.valueOf("application/vnd.ms-excel");
//
//    /**
//     * 通过构造器，指明当前转换器，转换到相应的数据类型
//     */
//    public XlsToHttpMessageConverter() {
//        super(EXCEL_TYPE);
//    }
//
//    /**
//     * 指定什么Class,进行当前方式的数据转换
//     */
//    @Override
//    protected boolean supports(Class<?> aClass) {
//
//        return (AjaxResponse.class == aClass);
//    }
//
//    /**
//     * 针对入参进行反序列化的过程  @RequestBody
//     */
//    @Override
//    protected AjaxResponse readInternal(Class<? extends AjaxResponse> aClass, HttpInputMessage httpInputMessage) throws IOException, HttpMessageNotReadableException {
//        return null;
//    }
//
//    /**
//     * 针对响应过程进行序列化处理， @ResponseBody
//     * 我们将返回 application/vnd.ms-excel 格式的数据
//     */
//    @Override
//    protected void writeInternal(AjaxResponse ajaxResponse, HttpOutputMessage httpOutputMessage) throws IOException, HttpMessageNotWritableException {
//
//        final Workbook workbook = new HSSFWorkbook();
//        final Sheet sheet = workbook.createSheet();
//
//        final Row row = sheet.createRow(0);
//        row.createCell(0).setCellValue(ajaxResponse.getMessage());
//        row.createCell(1).setCellValue(ajaxResponse.getData().toString());
//
//        workbook.write(httpOutputMessage.getBody());
//    }
//}
